﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Granite.DataAnnotations;

namespace Rifts.Models.Characters
{
	partial class Character
	{
		//Basic Stats
		public int Attacks
		{
			get { return Get<int>("Attacks"); }
			set
			{
				Set(value, "Attacks");
				RecalculateStyles();
			}
		}

		public int Actions
		{
			get { return Get<int>("Actions"); }
			set
			{
				Set(value, "Actions");
				RecalculateStyles();
			}
		}

		[CalculatedField("InitiativeBase,InitiativeFromPP")]
		public int Initiative
		{
			get { return InitiativeBase + InitiativeFromPP; }

		}

		public int InitiativeBase
		{
			get { return Get<int>("InitiativeBase"); }
			set
			{
				Set(value, "InitiativeBase");
				RecalculateStyles();
			}
		}

		[CalculatedField("PerceptionBase,PerceptionFromIQ")]
		public int Perception
		{
			get { return PerceptionBase + PerceptionFromIQ; }
		}

		public int PerceptionBase
		{
			get { return Get<int>("PerceptionBase"); }
			set { Set(value, "PerceptionBase"); }
		}

		public int StrikeBase
		{
			get { return Get<int>("StrikeBase"); }
			set { 
				Set(value, "StrikeBase");
				RecalculateStyles();
			}
		}

		public int DodgeBase
		{
			get { return Get<int>("DodgeBase"); }
			set
			{
				Set(value, "DodgeBase");
				RecalculateStyles();
			}
		}


		//Hand to Hand Combat

		/// <summary>
		/// Bonsus to Strike, usually this is melee only
		/// </summary>
		public int MeleeStrikeBase
		{
			get { return Get<int>("MeleeStrikeBase"); }
			set
			{
				Set(value, "MeleeStrikeBase");
				RecalculateStyles();
			}
		}

		[CalculatedField("StrikeFromPP,MeleeStrikeBase,StrikeBase")]
		public int MeleeStrike
		{
			get { return StrikeFromPP + MeleeStrikeBase + StrikeBase; }
		}

		public int Parry
		{
			get { return Get<int>("Parry"); }
			set
			{
				Set(value, "Parry");
				RecalculateStyles();
			}
		}

		public int MeleeDodgeBase
		{
			get { return Get<int>("MeleeDodgeBase"); }
			set
			{
				Set(value, "MeleeDodgeBase");
				RecalculateStyles();
			}
		}

		[CalculatedField("ParryDodgeFromPP,MeleeDodgeBase,DodgeBase")]
		public int MeleeDodge
		{
			get { return ParryDodgeFromPP + MeleeDodgeBase + DodgeBase; }
		}

		public int AutoDodgeBase
		{
			get { return Get<int>("AutoDodgeBase"); }
			set
			{
				Set(value, "AutoDodgeBase");
				RecalculateStyles();
			}
		}

		/// <summary>
		/// This is the Automatic Dodge bonus IF the character has the "Auto Dodge" ability.
		/// </summary>
		[CalculatedField("ParryDodgeFromPP,AutoDodgeBase")]
		public int AutoDodge
		{
			get { return ParryDodgeFromPP + AutoDodgeBase; }
		}

		/// <summary>
		/// Roll with Punch/Impact
		/// </summary>
		public int Roll
		{
			get { return Get<int>("Roll"); }
			set
			{
				Set(value, "Roll");
				RecalculateStyles();
			}
		}

		public int Disarm
		{
			get { return Get<int>("Disarm"); }
			set
			{
				Set(value, "Disarm");
				RecalculateStyles();
			}
		}

		public int PullPunch
		{
			get { return Get<int>("PullPunch"); }
			set
			{
				Set(value, "PullPunch");
				RecalculateStyles();
			}
		}

		//Ranged Combat

		public int RangedStrikeBase
		{
			get { return Get<int>("RangedStrikeBase"); }
			set
			{
				Set(value, "RangedStrikeBase");
				RecalculateStyles();
			}
		}

		[CalculatedField("StrikeFromPP,RangedStrikeBase,StrikeBase")]
		public int RangedStrike
		{
			get { return RangedStrikeBase + StrikeBase; }
		}

		public int RangedDodgeBase
		{
			get { return Get<int>("RangedDodgeBase"); }
			set
			{
				Set(value, "RangedDodgeBase");
				RecalculateStyles();
			}
		}

		[CalculatedField("ParryDodgeFromPP,RangedDodgeBase,DodgeBase")]
		public int RangedDodge
		{
			get { return ParryDodgeFromPP + RangedDodgeBase + DodgeBase; }
		}


		public int CalledShot
		{
			get { return Get<int>("CalledShot"); }
			set
			{
				Set(value, "CalledShot");
				RecalculateStyles();
			}
		}

		public int AimedShot
		{
			get { return Get<int>("AimedShot"); }
			set
			{
				Set(value, "AimedShot");
				RecalculateStyles();
			}
		}

		//other


		public FightingStyleCollection FightingStyles
		{
			get { return GetNew<FightingStyleCollection>("FightingStyles"); }
		}

		internal void RecalculateStyles()
		{
			foreach (var option in FightingStyles)
				option.UpdateCalculatedValues(this);
		}

		public UnarmedAttackCollection UnarmedAttacks
		{
			get { return GetNew<UnarmedAttackCollection>("UnarmedAttacks"); }
		}

		public AbilityCollection CombatAbilities
		{
			get { return GetNew<AbilityCollection>("CombatAbilities"); }
		}

		public WeaponProficiencyCollection Proficiencies
		{
			get { return GetNew<WeaponProficiencyCollection>("Proficiencies"); }
		}
	}

}




